package com.jzcn.admin.controller.system;

import com.jzcn.admin.annotation.ServerLog;
import com.jzcn.admin.base.BaseController;
import com.jzcn.common.dto.common.KeyWordDTO;
import com.jzcn.common.dto.system.position.PositionRecordDTO;
import com.jzcn.common.response.ResponseResult;
import com.jzcn.common.utils.JzPage;
import com.jzcn.service.EntPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Api(value = "Position", tags = "岗位管理")
@RequestMapping("/api/position")
public class PositionController extends BaseController {

    @Resource
    EntPositionService sysPositionService;

    @ApiOperation("岗位列表")
    @GetMapping("/page")
    @RequiresPermissions("system:position:page")
    @ServerLog(value ="岗位列表", code= "system:position:page")
    public ResponseResult<JzPage<PositionRecordDTO>> page(KeyWordDTO dto) {
        return ResponseResult.success(sysPositionService.listPage(dto));
    }

    @ApiOperation("新增岗位")
    @PostMapping("/create")
    @RequiresPermissions("system:position:add")
    @ServerLog(value ="新增岗位", code= "system:position:add")
    public ResponseResult<Boolean> create(@RequestBody PositionRecordDTO dto) {
        dto.setCreateUserId(getUserId());
        return ResponseResult.success(sysPositionService.create(dto));
    }

    @ApiOperation("更新岗位")
    @PutMapping("/update/{id}")
    @RequiresPermissions("system:position:update")
    @ServerLog(value ="更新岗位", code= "system:position:update")
    public ResponseResult<Boolean> update(@RequestBody PositionRecordDTO dto,@PathVariable("id") Integer id) {
        dto.setId(id);
        return ResponseResult.success(sysPositionService.update(dto));
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    @RequiresPermissions("system:position:delete")
    @ServerLog(value ="删除岗位", code= "system:position:delete")
    public ResponseResult<Boolean> delete(@PathVariable("id") Integer id) {
        return ResponseResult.success(sysPositionService.delete(id));
    }

}
